wx.config({
	debug: false,
	appId: '${appId}',
	timestamp: '${timestamp}',
	nonceStr: '${nonceStr}',
	signature: '${signature}',
	jsApiList: [
		'checkJsApi',
		'onMenuShareTimeline',
		'onMenuShareAppMessage',
		'onMenuShareQQ',
		'onMenuShareWeibo',
		'hideMenuItems',
		'showMenuItems',
		'hideAllNonBaseMenuItem',
		'showAllNonBaseMenuItem',
		'translateVoice',
		'startRecord',
		'stopRecord',
		'onRecordEnd',
		'playVoice',
		'pauseVoice',
		'stopVoice',
		'uploadVoice',
		'downloadVoice',
		'chooseImage',
		'previewImage',
		'uploadImage',
		'downloadImage',
		'getNetworkType',
		'openLocation',
		'getLocation',
		'hideOptionMenu',
		'showOptionMenu',
		'closeWindow',
		'scanQRCode',
		'chooseWXPay',
		'openProductSpecificView',
		'addCard',
		'chooseCard',
		'openCard'
	]
});

wx.error(function(res) {
	//  alert(res.errMsg);
});
var share_url = window.location.href;
//默认分享数据
var shareData = typeof(shareData) === 'undefined' ? {
	title: document.title,
	desc: 'Share Descption',
	link: share_url,
	imgUrl: 'http://img.weizhi.so/wx.png'
} : shareData;
//新版微信
wx.ready(function() {
	wx.onMenuShareAppMessage(shareData);
	wx.onMenuShareTimeline(shareData);
	wx.onMenuShareWeibo(shareData);
	wx.onMenuShareQQ(shareData);
});
var img = {};
img.upload = function(d) {
	var images = {localId: [],serverId: []};
	var imgArray = [];
	wx.chooseImage({
		count: d.count > 8 ? 9 : d.count, 
		sizeType: d.sizeType, 
		sourceType: d.sourceType, 
		success: function(res) {
			images.localId = res.localIds;
			var i = 0,
			length = images.localId.length;
			$(function upfile() {
				wx.uploadImage({
					localId: images.localId[i],
					success: function(res) {
						i++;
						images.serverId.push(res.serverId);
						//imgtext = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=&media_id=" + res.serverId;
						$.ajax({
							type: "get",
							url: "/api/qiniu/fetch?serverid=" + res.serverId + "&key=Station&appid=${this_appid!1}",
							dataType: "json",
							async:true,
							success: function(ret) {
								if(ret.state) {
									$("#image_url").text(ret.data);
									$("#image").attr("image", ret.data);
									img = ret.data;
									$(".upload-img-warp").prepend("<div class='wraps'><img class='lazy_img' src='" + img + "?imageView2/1/w/200' width='100%' /><span class='del'></span></div>")
									imgArray.unshift(img);
									$("#img").val(imgArray.join(','))
									if(i < length) {
										upfile();
									}else{
										d.success(imgArray);
									}
									return;
								} else
									alert(ret.msg);
							},
							failed: function() {
								alert("网络请求错误，请稍后再试！");
							}
						});
					},
					fail: function(res) {
						layer.msg(JSON.stringify(res));
						i++;
					}
				});
			});
		}
	});
}